layui.use([ 'jquery', 'layer', 'form', 'table','laydate','element'  ], function() {
    var $ = layui.jquery;
    var laydate=layui.laydate;

    laydate.render({
        elem:'#year',

        value:new Date()
    });
    $("#doSearch").click(function(){
        getData();
    });

    function getData(){
        var year=$("#year").val();
        if(year===""){
            year=new Date().getFullYear();
        }
        $.post("departmentCenter/currentFinance",{current:year},function(data){
            var total=0;
            $.each(data, function (index, item) {
                total+=Number(item.value);
            });
            $("#current").val(total);


            var dom = document.getElementById("container");
            var myChart = echarts.init(dom);
            var app = {};
            option = null;
            option = {
                title : {
                    text: '门诊当天统计',
                    subtext: '真实有效',
                    x:'center'
                },
                tooltip : {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    left: 'left',
                    data: data.name
                },
                series : [
                    {
                        name: '',
                        type: 'pie',
                        radius : '55%',
                        center: ['50%', '60%'],
                        data:data,
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
            ;
            if (option && typeof option === "object") {
                myChart.setOption(option, true);
            }
        });
    }
    getData();
})